package xj.model.uml;

import static xj.model.uml.UMLModelConstants.ATTR_KIND;

public class SuperType extends Classifier { 
  
  public enum Kind { 
      Default, 
      Generalization, 
      Realization;

    public static Kind toKind(String s) {
      if (s != null) {
	s = s.toLowerCase(); 
	if ("generalization".equals(s)) {
	  return Generalization;
	} else if ("realization".equals(s)) {
	  return Realization;
	}
      }
      return Default; 
    }
  }

  public SuperType() {
    this(null, Kind.Default);
  }

  public SuperType(String name) {
    this(name, Kind.Generalization);
  }

  public SuperType(String name, Kind kind) {
    super(name);
    this.kind = kind;
    setAttribute(ATTR_KIND, kind);

    destructable = false;
    preserved = true;
  }

  public void setKind(Kind kind) {
    this.kind = kind;
    setAttribute(ATTR_KIND, kind);
  }

  public Kind getKind() { 
    return kind; 
  }

  @Override
  public Object clone() throws CloneNotSupportedException {
    SuperType t = (SuperType) super.clone();
    t.setKind(kind);
    return t; 
  }

  @Override
  public boolean equals(Object o) {
    if (this == o) {
      return true;
    }
    if (o instanceof SuperType) {
      SuperType t = (SuperType) o;
      return (name.equals(t.name) && kind == t.kind);
    }
    return false;
  }

  protected Kind kind; 

}